package main

import (
	"fmt"
	"sync"
	"time"
)

var wg sync.WaitGroup

func main() {
	//计时
	start := time.Now()
	defer func() {
		cost := time.Since(start)
		fmt.Println("cost=", cost)
	}()
	wg.Add(3)
	go foo()
	go bar()
	wg.Done()
	wg.Done()
	wg.Wait()
}

func foo() {
	for i := 0; i < 5; i++ {
		fmt.Println("Foo:", i)
		time.Sleep(time.Second *2)
	}

}

func bar() {
	for i := 0; i < 5; i++ {
		fmt.Println("Bar:", i)
		time.Sleep(time.Second)
	}

}
